package com.workcell.workdata.im.component.predicate;

import com.farsunset.cim.constant.ChannelAttr;
import io.netty.channel.Channel;

import java.util.List;
import java.util.function.Predicate;

/**
 * 发时消息，终端类型过滤
 */
public class ChannelFilterPredicate implements Predicate<Channel> {

    private final List<String> channelFilter;

    public static Predicate<Channel> of(List<String> channelFilter){
        return new ChannelFilterPredicate(channelFilter);
    }

    public ChannelFilterPredicate(List<String> channelFilter) {
        this.channelFilter = channelFilter;
    }

    @Override
    public boolean test(Channel channel) {
        String clientChannel = channel.attr(ChannelAttr.CHANNEL).get();
        return !channelFilter.contains(clientChannel);
    }

}
